# Testing Tab Texts
tabs = ['<b>Section 1</b><br/>First Section', 
        '<b>Section 2</b><br/>Second Section', 
        '<b>Section 3</b><br/>Third Section', 
        '<b>Section 4</b><br/>Fourth Section', 
        '<b>Section 5</b><br/>Fifth Section']

# Tab Texts Genearators
def NumberList( start=1, end=100 ):
    return [ num for num in range(start,end+1) ]

def NumeralList( start=1, end=10 ):
    numerals = [ 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X' ]
    return [ numerals[i] for i in range(start-1,end) ]
    
# Tab Sizes
tabSize = { '8': (792,612),
            '9': (792,648) }

def tabber( tabs,
            text_size=11, text_face='Helvetica', text_color='black', text_orientation=90,
            tab_num=5, tab_size=tabSize['9'], tab_indent=36, tab_margin=(9,9), tab_orientation='portrait', pad_last=True ):

    import os
    from reportlab.pdfgen.canvas import Canvas
    from reportlab.platypus import Paragraph
    from reportlab.lib import styles

    # Create PDF Canvas and Paragraph Style
    filename = 'Tabber.pdf'
    canvas = Canvas( filename, tab_size )
    style = styles.getSampleStyleSheet()['Normal']
    
    # Modify Style 
    style.fontSize = text_size
    style.fontName = text_face
    #style.textColor = text_color
    style.alignment = 1 # 0,1,2 : Left, Center, Right
    style.borderWidth = 1

    # Calculate Available Paragraph Space
    tab_width = (tab_size[0]-(tab_indent*2))/tab_num
    tab_height = 72

    # Create Tabs
    tab_position = 0
    for tab in tabs:
        # Create Paragraph and Calculate Actual Paragraph Size
        p = Paragraph( tab, style )
        w,h = p.wrapOn( canvas, tab_width, tab_height )
        
        # Calculate Tab Position & Draw Text
        x = tab_indent + tab_width*tab_position
        y = tab_size[1] - tab_margin[1] - h
        p.drawOn( canvas, x, y )
        
        # Finish Page and Update Tab Position
        canvas.showPage()
        if tab_position<tab_num-1: tab_position += 1
        else: tab_position = 0

    # Write Out PDF
    canvas.save()
    os.startfile( filename )
